# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Sergej Pupykin <arch+pub@sergej.pp.ru>
# Contributor: Leonard de Ruijter <leonard@aur.archlinux.org>
# Contributor: Hubert Kario <hubert@kario.pl>
# Contributor: Artyom Smirnov <smirnoffjr@gmail.com>

pkgname=opendbx
pkgver=1.4.6
pkgrel=12
pkgdesc='Extremely lightweight but extensible database access library written in C'
arch=('loong64' 'x86_64')
url='https://www.linuxnetworks.de/doc/index.php/OpenDBX'
license=('LGPL')
depends=(
  'libfbclient'
  'mariadb-libs'
  'postgresql-libs'
  'sqlite'
  'freetds'
)
makedepends=('doxygen' 'docbook2x')
source=(
  "https://linuxnetworks.de/opendbx/download/${pkgname}-${pkgver}.tar.gz"
  'https://src.fedoraproject.org/rpms/opendbx/raw/rawhide/f/opendbx-1.4.6-dynamic-exceptions.patch'
  'https://src.fedoraproject.org/rpms/opendbx/raw/rawhide/f/opendbx-1.4.6-freetds-fix.patch'
  'https://src.fedoraproject.org/rpms/opendbx/raw/rawhide/f/opendbx-1.4.6-doxygen-1.9.1.patch'
)
sha512sums=('dd6d53d29157057dbf4e273fd82c7694e8bc626d3409d6ab9c25627a0fec96418326550fa8004b5341facdc4cd8aae12516224e8bb84e2562482885780ff0e55'
            '02f7d254e4c3d832a6c3dc86b96cedc3356139aace0953022e0008160e03ccd0a400d1f96da5a63d1a9ec5b8a7197db46d28e4b80d60b11ede1adf6ba283ec72'
            'd08b2b1c6a1a457bfdd4687d444fc94cb71f0c8ed6c2e15093ceb51ccd82830d5963446b39987dd5ee10581c46c3aaf47da08108a8cba29dd1aee23c41735e06'
            '788dd22119154d5029b7bb427885e2474e06a51ebf4a8e8b0c5b08a9f89124c0e0df5a3260a475c308cd78cba97758a1b9873185538347e3c3bfe87a47bd8e9d')
b2sums=('0a6c983ac1ebdc3ad9390185938f32e13ba9ff2ced6d41390421e1e3a1e9eb639a85d89da7ce2dd67f05fd2fcaebb2f53146f43678e548511403d8cdc4de88da'
        'd6ea8d01a908cfe5bb9fe659822b79d0335a5c27b25062cdf24a1fb7efca1f1ba79057dad5e7d3dc9258785d3e3113547eaf31c1c69fa422ed9e587b287ac042'
        '0aa5f782068e0ef516324fd378221abae239f17e662c3f2dbd0a8dacdaa703cbe35098d542cc95853344677c3f065075931775e6f95ce22007b4baaf139a3b95'
        '8b380461e4a76a05012560fe4e7517faece1be214db66aaee5271e972a880661016f9870d8b92c5d92a4573718a7533e6c537ee2afb1d8cdcf53495052a2e5e7')

prepare() {
  cd "$pkgname-$pkgver"

  # patches/fixes borrowed from Fedora. <3.
  patch -p1 -i "$srcdir/opendbx-1.4.6-dynamic-exceptions.patch"
  patch -p1 -i "$srcdir/opendbx-1.4.6-freetds-fix.patch"
  patch -p1 -i "$srcdir/opendbx-1.4.6-doxygen-1.9.1.patch"

  # To fix Doxygen parsing issue
  ln -s api lib/opendbx/api.dox
  # C++ API file must have extension .hpp to be parsed correctly by doxygen
  cp lib/opendbx/api lib/opendbx/api.hpp

  # regenerate stale libtool files
  autoreconf -vfi

  # fix hardcoded RPATH issue
  sed \
    -e 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' \
    -e 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' \
    -i m4/libtool.m4
}

build() {
  cd "$pkgname-$pkgver"

  export CPPFLAGS=${CPPFLAGS}" -I/usr/include/mysql"

  ./configure \
    --with-backends="firebird mysql mssql odbc pgsql sqlite3 sqlite3 sybase" \
    --prefix=/usr

  make all
}
check() {
  cd "$pkgname-$pkgver"

  make check
}

package() {
  cd "$pkgname-$pkgver"

  make DESTDIR="$pkgdir" install
}

# vim:set ts=2 sw=2 et:
